﻿
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sproc_Flow_DeleteStep_V2]') AND type in (N'P', N'PC'))
    DROP PROCEDURE [dbo].[sproc_Flow_DeleteStep_V2];
GO
CREATE PROCEDURE [dbo].[sproc_Flow_DeleteStep_V2]
    @FlowID int,
    @StepID int
/*
===================================================

功能:    删除步骤
参数:
    @FlowID int            ：    流程ID
    @StepID int            ：    步骤ID

===================================================
*/
AS
BEGIN
SET NOCOUNT ON;
SET XACT_ABORT ON;

BEGIN TRANSACTION;

--删除绑定
DELETE FROM dbo.uds_flow_member_bind WHERE flow_id = @flowID and step_id = @stepid;

--删除步骤
DELETE FROM dbo.UDS_Flow_Jump WHERE Flow_id = @flowID and (Step_id = @stepid OR To_Step_ID = @stepid);
DELETE FROM dbo.uds_flow_step WHERE flow_id = @flowID and step_id = @stepid;

--更新绑定
UPDATE dbo.UDS_Flow_Member_Bind SET step_id = step_id -1 WHERE flow_id = @flowID and step_id > @stepid;

--更新步骤
UPDATE dbo.UDS_Flow_Step SET step_id = step_id -1 WHERE flow_id = @flowID and step_id > @stepid;

COMMIT TRANSACTION;
RETURN 0;

END
GO
